package hn.cch.version.lts11.feature;

import java.io.IOException;
import java.lang.System.Logger.Level;
import java.lang.System.LoggerFinder;

public class ProcessHandleDemo {

    private static final System.Logger LOGGER = System.getLogger("Main");

    public static void testLogger(final String[] args) {
        LOGGER.log(Level.INFO, "Run!");
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        ProcessBuilder processBuilder = new ProcessBuilder("top")
            .inheritIO();
        ProcessHandle processHandle = null;
        try {
            processHandle = processBuilder.start().toHandle();
            processHandle.onExit().whenCompleteAsync((handle, throwable) -> {
                if (throwable == null) {
                    System.out.println(handle.pid());
                } else {
                    throwable.printStackTrace();
                }
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}
